<template>
  <div class="box">
    <div class="list">
      <div class="radio">
        <van-checkbox
          v-model="typeItem.flag"
          checked-color="#2BAB7B"
          @click="toggleClick"
        ></van-checkbox>
      </div>
      <div class="type">
        <div class="typeImg">
          <img :src="typeItem.data.small_img" class="auto-img" />
        </div>
        <div class="text">
          <div class="textTop">
            {{ typeItem.data.name }}
            <span class="specification">{{ typeItem.data.rule }}</span>
          </div>
          <div class="textCenter">{{ typeItem.data.enname }}</div>
          <div class="price">￥{{ typeItem.data.price }}</div>
        </div>
        <div class="select-box">
          <div class="selector">
            <van-stepper
              v-model="count"
              theme="round"
              button-size="22"
              disable-input
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "shopList",
  data() {
    return {
      count: 1,
    };
  },
  props: {
    typeItem: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  watch: {
    count() {
      this.addCount();
      // 更新总价格
      this.$store.commit("control",{count:this.count,sid:this.typeItem.data.sid})
    },
  },
  methods: {
    addCount() {
      let sid = this.typeItem.data.sid;
      let count = this.count;
      let data = {
        sid,
        count,
      };
      this.axios({
        method: "post",
        url: "/modifyShopcartCount",
        data,
      })
        .then((res) => {
          // if(res.data.code===6000){
          //   console.log(res);
          // }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    toggleClick() {
      this.$store.commit("getAllData");
      this.$store.commit("setPrice");
    },
  },
  created() {
    this.count = this.typeItem.data.count;
  },
};
</script>
<style lang="less" scoped>
@import url("../assets/base.less");
.box {
  width: 94%;
  margin: 0px auto;
  .list {
    display: flex;
    height: 90px;
    padding: 10px;
    align-items: center;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0px 2px 8px rgb(204, 200, 200);
    position: relative;
    .type {
      display: flex;
      .typeImg {
        height: 80px;
        width: 80px;
        margin-left: 10px;
      }
      .text {
        margin-left: 10px;
        display: flex;
        padding-top: 3px;
        flex-direction: column;
        .textTop {
          font-size: 15px;
          font-family: SimHei;
          color: #2c2e2e;
          .specification {
            font-size: 14px;
            color: #a09c9c;
            margin-left: 10px;
          }
        }
        .textCenter {
          font-size: 12px;
          color: #a09c9c;
          margin-top: 7px;
        }
        .price {
          font-size: 14px;
          color: @mainColor;
          font-weight: bold;
          margin-top: auto;
        }
      }
      .select-box {
        position: absolute;
        height: calc(~"100% - 20px");
        display: flex;
        right: 0px;
        top: 10px;
        padding-right: 10px;
        .selector {
          margin-top: auto;
        }
      }
    }
  }
}
/deep/ .van-stepper--round .van-stepper__plus {
  background-color: @mainColor;
}
/deep/ .van-stepper--round .van-stepper__minus {
  color: @mainColor;
  border-color: @mainColor;
}
</style>